package utils

import (
	"fmt"
)

type ListNode struct {
	Val  int
	Next *ListNode
}

// GenList GenList
func GenList(nums []int) *ListNode {
	if nums == nil || len(nums) == 0 {
		return nil
	}
	nilhead := &ListNode{}
	res := nilhead
	for ii := range nums {
		res.Next = &ListNode{Val: nums[ii]}
		res = res.Next
	}
	return nilhead.Next
}

// PrintList PrintList
func (n *ListNode) PrintList() {
	fmt.Println("PrintList")
	head := n
	for head != nil {
		fmt.Println(head.Val)
		head = head.Next
	}
}
